package com.yeqian.user.service.impl;

import com.yeqian.user.mapper.UserInfoMapper;
import com.yeqian.user.service.UserSessionService;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Service
public class UserSessionServiceImpl implements UserSessionService {

    @Resource
    private UserInfoMapper userInfoMapper;
    @Override
    public String getCurrentUserId() {
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        User user = (User)principal;
        return userInfoMapper.getUserByName(user.getUsername()).getId();
    }

}
